-- CALC_WINNER_STONE_BONUS

-- 计算胜利者石柱奖励
-- @param user      玩家对象
-- @param bonus     奖励
return function(user, bonus)
    if type(bonus) == 'table' and #bonus > 0 then
        -- 如果传入了配置的奖励，直接使用
        return { ["bonus"] = bonus }
    end
    -- TODO
    local layer = DungeonM.currentLayer();
    local dungeonId = DungeonM.getDungeonId();
    local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");

    local hp = math.modf((30 + layer) * (60 + layerFix) / 200);
    local sp = math.modf(20 + layer / 2);

    local rand1 = DungeonM.getRandSeed("winner_stone_bonus") % 100;
    -- 大血瓶、大蓝瓶、探索点（40%、30%、30%）
    local arrAmount = {
        {["bonus"] = { { 2, "hp", hp, } }, ["ratio"] = 40},
        {["bonus"] = { { 2, "mp", 9, } }, ["ratio"] = 30},
        {["bonus"] = { { 2, "search_point", sp, } }, ["ratio"] = 30},
    };

    local bonus = fetchElemBySeed(arrAmount, rand1)["bonus"];

    -- 获得1~3个“折弯的铜币”，概率分别为“40%、40%、20%”
    local rand2 = DungeonM.getRandSeed("winner_stone_bonus") % 100;
    local amount = 3;

    if rand2 < 40 then
        amount = 1;
    elseif rand2 < 80 then
        amount = 2;
    end

    table.insert(bonus, { 1, 7028, amount, });

    -- 奖励加成
    local prop = PropM.combine(user, "stone_bonus", 1);
    if (prop[2] > 0) then
        for index = 1, #bonus do
            -- 加成
            bonus[index][3] = PropM.apply(prop, bonus[index][3]);
        end
    end

    return {
        ["bonus"] = bonus,
    };
end
